

import java.util.*;

public class LetterCombinations {

    private static Map<String,String[]> numberMap=new HashMap<String,String[]>(){{
       put("1",new String[]{""});
       put("2",new String[]{"a","b","c"});
       put("3",new String[]{"d","e","f"});
       put("4",new String[]{"g","h","i"});
       put("5",new String[]{"j","k","l"});
       put("6",new String[]{"m","n","o"});
       put("7",new String[]{"p","q","r","s"});
       put("8",new String[]{"t","u","v"});
       put("9",new String[]{"w","x","y","z"});
    }};


    public static List<String> solution(String digits){
        List<String> res=new ArrayList<>();
        if(digits.isEmpty()){
            return res;
        }
        if(digits.length()==1){
            return Arrays.asList(numberMap.get(digits));
        }
        col(digits,0,res,new StringBuffer());
        return res;

    }

    public static void col(String digits,int index,List<String> res,StringBuffer stringBuffer){
        if(index==digits.length()){
            res.add(stringBuffer.toString());
        }else{
            String c = String.valueOf(digits.charAt(index));
            String[] numbers = numberMap.get(c);
            for (int i = 0; i < numbers.length; i++) {
                stringBuffer.append(numbers[i]);
                col(digits,index+1,res,stringBuffer);
                stringBuffer.deleteCharAt(index);
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(solution("234"));
    }
}
